package com.ittaoli.controller;

import com.ittaoli.entity.User;
import com.ittaoli.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public Object login(String username, String password, HttpSession session){
        User user = adminService.Admin(username, password);
        Map<String,Object> map=new HashMap<>();
        if(user!=null){
            map.put("code",1);
            map.put("data",user);
            session.setAttribute("loginUser",user);
            return map;
        }
        map.put("code",0);
        map.put("msg","用户名或密码错误");
        return map;
    }
    @RequestMapping("/repwd")
    public int modify(){
       return -1;
    }
}
